package com.ny.demo523;
import java.sql.*;
import java.util.Scanner;

public class LonginDemo {
    private static final String URL="jdbc:mysql://localhost:3306/usersdb";
    private static final String DB_USERNAME = "root";
    private static final String DB_PASSWORD = "123456";
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(URL,DB_USERNAME,DB_PASSWORD);
        String sql = "select * from usersdb where username = ? and password = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入用户名");
        String username = scanner.next();
        System.out.println("输入密码");
        String password = scanner.next();
        preparedStatement.setString(1,username);
        preparedStatement.setString(2,password);
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("chenggong");
        }
        else{
            System.out.println("shibai");
        }
        scanner.close();
    }
}